package etlkettle.demo.controller;

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleMissingPluginsException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.job.Job;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;

public class ExcelWithXML {
    public static void main(String[] args) throws KettleException {
        executeTrans();
//        String file = "C:\\Users\\Admin\\Documents\\test.kjb";
//        String[] params = {};
//        KettleEnvironment.init();
//        JobMeta jobMeta = new JobMeta(file,null);
//        Job job = new Job(null,jobMeta);
//        job.start();
//        job.waitUntilFinished();
//        long batchId = job.getBatchId();
//        System.out.println(batchId);
//        if (job.getErrors() > 0){
//            System.out.println(
//                    "There are errors during transformation exception!(传输过程中发生异常)");
//        }
    }
    private static void executeTrans() throws KettleException{
        String file = "C:\\Users\\Admin\\Documents\\test.ktr";
        String[] params = {};
        KettleEnvironment.init();
        TransMeta transMeta = new TransMeta(file);
        Trans trans = new Trans(transMeta);
        trans.execute(params);
        trans.waitUntilFinished();
        System.out.println(trans.getBatchId());
        if (trans.getErrors() > 0){
            System.out.println(
                    "There are errors during transformation exception!(传输过程中发生异常)");
        }
    }
}
